import 'package:flutter/material.dart';
import 'package:flutter_love/bean/detail_bean.dart';
import 'package:flutter_love/utils/progress_dialog_util.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebDetailView extends StatefulWidget {
  const WebDetailView({Key? key}) : super(key: key);

  @override
  _WebDetailViewState createState() => _WebDetailViewState();
}

class _WebDetailViewState extends State<WebDetailView> {
  late WebViewController _controller;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    DetailBean bean = ModalRoute.of(context)?.settings.arguments as DetailBean;
    return Scaffold(
      appBar: AppBar(
        title: Text(bean.title),
        centerTitle: true,
      ),
      body: WebView(
        initialUrl: bean.url,
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (controller) {
          _controller = controller;
        },
        onPageFinished: (url) {
          ProgressDialogUtil.dismiss(context);
        },
        onPageStarted: (url) {
          ProgressDialogUtil.showProgress(context);
        },
      ),
    );
  }
}
